<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>基础数据管理-项目信息新增</title>
    <script src="/scripts/boot.js"></script>
    <link href="/scripts/daterangepicker/js/daterangepicker.min.css" rel="stylesheet" type="text/css" />
    <script src="/scripts/daterangepicker/js/moment.js" type="text/javascript"></script>
    <script src="/scripts/daterangepicker/js/jquery.daterangepicker.min.js" type="text/javascript"></script>
    <script src="/scripts/daterangepicker/ux.daterangepicker.js" type="text/javascript"></script>
    <link href="/scripts/daterangepicker/css/skin.css" rel="stylesheet" type="text/css" />
    <style>
        html body .searchbox .mini-buttonedit-icon
        {
            /*background:url(static/scripts/daterangepicker/search.gif) no-repeat 50% 50%;*/
        }
    </style>
</head>
<body class="bg-white">
<div id="viewForm">
    <div class="title-info mb-20"><span>计划信息</span></div>
    <table class="table-bg" border="0" cellpadding="1" cellspacing="1" style="width:100%;table-layout:fixed;">
        <colgroup>
            <col width="135px"></col>
            <col width="50%"></col>
            <col width="135px"></col>
            <col width="50%"></col>
        </colgroup>
        <tr>
            <td class="text-titlebg"><span class="color-red">*</span>计划类型</td>
            <td>
                <select id="planType" name="planType" class="mini-combobox w250" ajaxType="post" url="/planExe/getByCode?code=100045" textField="value" valueField="id" errorMode="none" onvalidation="onChoseValidation" required="true" requiredErrorText="请选择" onvaluechanged="view.planTypeChanged"></select>
            </td>
            <td class="text-titlebg">
                <span class="color-red">*</span>选择项目计划
            </td>
            <td>
            	<select id="planCombo" name="planId" class="mini-combobox w250" url="/planExe/planList?planTypeId=0" textField="name" valueField="id" required="true"  errorMode="none" onvalidation="onChoseValidation" required="true" requiredErrorText="请选择"></select>
            </td>
        </tr>
        <tr>
            <td class="text-titlebg">
                <span class="color-red">*</span>业务板块
            </td>
            <td>
                <select id="busiMode" name="busiMode" class="mini-combobox w250" ajaxType="post" url="/businessType/listAll" textField="typeName" valueField="id" errorMode="none" onvalidation="onChoseValidation" required="true" requiredErrorText="请选择"></select>
            </td>
            <td class="text-titlebg"><span class="color-red">*</span>计划性质</td>
            <td>
                <select id="nodeProperty" name="nodeProperty" class="mini-combobox w250" ajaxType="post" url="/dictionary/listValues?name=nodeProperty" textField="value" valueField="id" errorMode="none" onvalidation="onChoseValidation" required="true" requiredErrorText="请选择"></select>
            </td>
        </tr>
        <tr>
            <td class="text-titlebg">
                <span class="color-red">*</span>计划起止时间
            </td>
            <td>
                <input id="date-range1" name="ssDate" class="uc-daterangepicker searchbox w250" />
            </td>
            <td class="text-titlebg">
                <span class="color-red">*</span>计划内容
            </td>
            <td>
                <input type="text" name="planNodeName" id="planNodeName" class="mini-textbox w250" required="true" errorMode="none" onvalidation="onNullValidation" requiredErrorText="请输入"　maxLength="48"/>
            </td>
        </tr>
        <tr>
            <td class="text-titlebg"><span class="color-red">*</span>执行人</td>
            <td>
                <input id="postPerson" name="postPerson" textName="postPersonName" required="true" allowInput="false" class="mini-buttonedit w250" onbuttonclick="common.onButtonEdit"/>
                <!--<input name="evaluateId" id="evaluateId" class="mini-treeselect w250" onbeforenodeselect="common.beforenodeselect" expandOnLoad="true" showTreeIcon="true" valueField="id" textField="name"   parentField="pid"   required="true"   vtype="maxLength:48"  errorMode="none" onvalidation="upChoseError" requiredErrorText="请选择"/>-->
            </td>
            <td class="text-titlebg">配合人</td>
            <td>
                <input id="cooperatePostPerson" name="cooperatePostPerson" textName="cooperatePostPersonName" allowInput="false" class="mini-buttonedit w250" onbuttonclick="common.onButtonEdit"/>
                <!--<input name="evaluate" id="evaluate" class="mini-treeselect w250" onbeforenodeselect="common.beforenodeselect" expandOnLoad="true" showTreeIcon="true" valueField="id" textField="name"   parentField="pid"  vtype="maxLength:48"  errorMode="none" onvalidation="upChoseError" requiredErrorText="请选择"/>-->
           </td>
        </tr>
        <tr>
            <td class="text-titlebg">
                配合起止时间
            </td>
            <td>
                <input id="date-range" name="cooperateDate" class="uc-daterangepicker searchbox w250" />
            </td>
            <td class="text-titlebg">配合事项</td>
            <td>
                <input type="text" name="cooperateMatters" class="mini-textbox w250"  errorMode="none" onvalidation="onNullValidation" requiredErrorText="请输入"　maxLength="255"/>
            </td>
        </tr>
        <tr>
            <td class="text-titlebg noEmpty">完成标准</td>
            <td colspan="3" class="wp">
                <textarea name="completeStandard" class="mini-textarea wtextarea" emptyText="" maxLength="255"></textarea>
            </td>
        </tr>
        <tr>
            <td class="text-titlebg noEmpty">工期说明</td>
            <td colspan="3" class="wp">
                <textarea name="deadlineDesc" class="mini-textarea wtextarea" emptyText="" maxLength="255"></textarea>
            </td>
        </tr>
        <tr>
            <td class="text-titlebg noEmpty">备注</td>
            <td colspan="3" class="wp">
                <textarea name="remark" class="mini-textarea wtextarea" emptyText="" maxLength="255"></textarea>
                <input name="id" id="planNodeId" class="mini-hidden"/>
            </td>
        </tr>
    </table>
    <div class="mini-fit"></div>
    <div class="chose-toolbar">
        <a class="chose-button" onclick="CloseWindow('close')">取消</a>
        <a class="chose-button save-button" onclick="view.save('save')">保存</a>
        <a class="chose-button save-button" onclick="view.save('aduit')">发送审批</a>
    </div>
</div>
<script src="/scripts/res/js/common.js"></script>
<script type="text/javascript">

    var post_flag,form,state,datas;
    var view = {
        init: function () {  
	        common.loadTree({
	            success : function(data){
	                //获取评价人
	                var evaluateId = mini.get("evaluateId");
	                evaluateId.loadList(data, "id", "pid");
	            }
	        });
	        common.loadTree({
	            success : function(data){

	                //获取评价人
	                var evaluate = mini.get("evaluate");
	                evaluate.loadList(data, "id", "pid");
	            }
	        });
            post_flag = false; //设置一个对象来控制是否进入AJAX过程
            mini.parse();
            form = new mini.Form("#viewForm");
        },
        planTypeChanged:function() {
		    var planType = mini.get("planType");
		    var planCombo = mini.get("planCombo");
		    var id = planType.getValue();
		    
		    var url = "/planExe/planList?planTypeId=" + id;
		    planCombo.setUrl(url);
		    
		},
        //保存
        save: function (e) {
            form.validate();
            var data = form.getData();//获取表单多个控件的数据
            if (form.isValid() == false) return;
            if (post_flag) return;

            data['plan.planType.id']=data.planType;
            delete data["planType"];
            data['plan.id']=data.planId;
            delete data["planId"];

            data['nodeName']=data.planNodeName;
            delete data["planNodeName"];
            
            data['nodeProperty.id']=data.nodeProperty;
            delete data["nodeProperty"];
            data['business.id']=data.busiMode;
            delete data["busiMode"];

            data['postPerson']=data.evaluateId;
            delete data["evaluateId"];
            data['cooperatePostPerson']=data.evaluate;
            delete data["evaluate"];
            

            data['beginDate']=new Date(data.ssDate.substring(0,10));
            data['endDate']=new Date(data.ssDate.substring(data.ssDate.length-10,data.ssDate.length));

        	var deadline=(new Date(data.ssDate.substring(data.ssDate.length-10,data.ssDate.length)).getTime()-new Date(data.ssDate.substring(0,10)).getTime())/(1000*60*60*24);
            
            data['deadline']=deadline;
            delete data["ssDate"];
			if(data.cooperateDate){
				 data['cooperateBeginDate']=new Date(data.cooperateDate.substring(0,10));
			     data['cooperateEndDate']=new Date(data.cooperateDate.substring(data.cooperateDate.length-10,data.cooperateDate.length));
			     delete data["cooperateDate"];
			}
           
            
            
            post_flag = true;
            $.ajax({
                url: ("/monthlyPlanExecution/save"),
                type: "post",
                data: data,
                success: function (msg) {
                    post_flag = false;
                    common.unmask();
                    if(e==='aduit'){
                    	if(msg.state){
                            common.loading("加载中");
                    		view.aduit(msg.message)
                    	}
                    }
                    if(e==='save'){
                         CloseWindow("ok");
                    }
                },
                error: function (errorMsg) {
                    post_flag = false;
                    common.unmask();
                }
            });
        }, //发送审批
        aduit: function(id){
            $.ajax({
				type : "post",
				url : "/loggerService/startPost",
				data : {"id":id,"formSign":"CDJHGJJHZXXZ_01","workFlowId":"CDJHGLJHZXXZJDSP","jumpUrl":"/program/planNode/workflow.html?id="+id,"url":"/act/taskApi/start","exampleEntity":"planNodeNew"},
				success : function(msg) {
					if(msg.message==="ok"){
		                common.loading("加载中");
						view.updateAuditState(id);
					}
				}
			});
		}, //改变数据状态
        updateAuditState: function(id){
            $.ajax({
				type : "post",
				url : "/planExe/edit",
				data : {"id":id},
				success : function(msg) {
                    CloseWindow("ok");
				}
			});
		},
//    数据展示
        SetData: function (data) {
            data = mini.clone(data);
            state = data.state;
            if(data.state=="edit"){
                common.loading("加载中");
                $.ajax({
                    url:"/monthlyPlanExecution/newInfo?id=" + data.id,
                    type: "post",
                    success: function (text) {
                    	var obj = JSON.parse(text);
                        //跨页面传递的数据对象，克隆后才可以安全使用
                        datas = mini.decode(obj.body[0]);   //反序列化成对象
                        form.setData(datas);             //设置多个控件数据
                        mini.get("date-range1").setValue(datas.beginDate +" ~ " +datas.endDate);
                        if(datas.cooperateBeginDate&&datas.cooperateEndDate){
                            mini.get("date-range").setValue(datas.cooperateBeginDate +" ~ " +datas.cooperateEndDate);
                        }
                        mini.get("busiMode").setValue(datas.business);
                        setTimeout(function(){},1000);
                        mini.get("evaluateId").setValue(datas.postPerson);
                        mini.get("evaluate").setValue(datas.cooperatePostPerson);
                        mini.get("planNodeName").setValue(datas.nodeName);
                        
                        mini.get('planType').setValue(datas.planType);
                        view.planTypeChanged();
                        mini.get('planCombo').setValue(datas.planId);
                        
                        common.unmask();
                    }
                });
            }else{
                mini.get("planNodeId").setValue("");
            }
        }
    };
    view.init();
</script>
</body>
</html>